<?php

declare(strict_types=1);

namespace Zyucv7\Components\AI\LLM\ClientType;

use Zyucv7\Components\AI\LLM\Client as LLMClient;
use Zyucv7\Components\AI\LLM\Exceptions\ClientException as LLMClientException;

/**
 * 通用的LLM API - 
 */
class Zhipu extends LLMClient
{

    protected string $apiKey = '6a19e4134b766960c9ffca3984cd608e.VyyNuhC4jJNMzlDr'; // API Key
    protected string $baseUrl = 'https://open.bigmodel.cn/api'; // API 公用地址
    protected string $model = 'glm-4.5-flash'; // 默认免费模型
    protected string $sendUrl = '/paas/v4/chat/completions'; // 固定API 请求地址

    private function getContent() {
        return '{
            "model": "glm-4.5-flash",
            "do_sample": true,
            "stream": false,
            "thinking": {
                "type": "disabled"
            },
            "temperature": 0.6,
            "top_p": 0.95,
            "stream": false,
            "tool_stream": false,
            "response_format": {
                "type": "text"
            },
            "messages": [
                {
                    "role": "system",
                    "content": "'.$this->systemPrompt.'"
                },
                {
                    "role": "user",
                    "content": "'.$this->userPrompt.'"
                }
            ]
        }';
    }
    protected function buildOptions(): void
    {
        if(!$this->systemPrompt || !$this->userPrompt) {
            throw LLMClientException::InvalidArgument('System prompt or user prompt is not set.');
        }

        $this->jsonStr = $this->getContent();
    }
}
